#include "behavior_tree_repeat_policy.h"
#include <behaviortree_cpp_v3/decorators/repeat_node.h>

namespace policy
{
BehaviorTreeRepeatPolicy::BehaviorTreeRepeatPolicy(const std::string &name, int repeat_count)
    : BehaviorTreePolicy(name)
{
    policy_tree_node_ = std::make_unique<BT::RepeatNode>(name + "_repeat_node", repeat_count);
}
BehaviorTreeRepeatPolicy::~BehaviorTreeRepeatPolicy() = default;

void BehaviorTreeRepeatPolicy::setRetryCount(int32_t count)
{
    auto node = dynamic_cast<BT::RepeatNode *>(policy_tree_node_.get());
    if (nullptr == node)
    {
        throw std::runtime_error("behavior tree repeat policy case fail");
    }
    node->setRetryCount(count);
}
int32_t BehaviorTreeRepeatPolicy::getRetryCount() const
{
    auto node = dynamic_cast<BT::RepeatNode *>(policy_tree_node_.get());
    if (nullptr == node)
    {
        throw std::runtime_error("behavior tree repeat policy case fail");
    }
    return node->getRetryCount();
}
}
